package com.huifaapp.mall.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.ShoppingCartActivity;
import com.huifaapp.mall.adapter.SpecificatAdapter;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.specificatBean;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import static com.huifaapp.mall.uitils.Contig.typex;

/**
 * Created by 段昱 on 2017/12/14.
 */

public class SpecificationsFramgnet extends Fragment {

    private View view;
    private RecyclerView specifications_recyclerView;
    private ArrayList<specificatBean.DataBean> stringlist;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_specifications, container, false);
        initView();
        initHttp();
        return view;
    }

    private void initHttp() {
        Bundle bundle = getArguments();//从activity传过来的Bundle
        if (bundle!=null){
            String shopid = bundle.getString("shopid");
            OkHttpUtils.post().addParams("id", shopid).url(ApiManager.BASE_NIUPAI_URL+typex+"/getSpecs").build().execute(new StringCallback() {
                @Override
                public void onError(Request request, Exception e) {

                }

                @Override
                public void onResponse(String response) {
                    Log.e("kankan ",response);
                    Gson  gson=new Gson();
                    specificatBean specificatBean = gson.fromJson(response, specificatBean.class);
                    stringlist = new ArrayList<>();
                    stringlist.addAll(specificatBean.getData());
                    SpecificatAdapter SpecificatAdapter=new SpecificatAdapter(stringlist,getActivity());
                    specifications_recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
                    specifications_recyclerView.setAdapter(SpecificatAdapter);

                }
            });
        }

    }



    private void initView() {
        specifications_recyclerView = (RecyclerView) view.findViewById(R.id.specifications_RecyclerView);
    }
}
